<?php
namespace Home\Controller;
use Think\Model;
use Think\Controller;
use Think\Verify;
use Think\Image;
use Think\Upload;
use Think\Page;
class ShouyeController extends Controller {
    public function index(){
        $theuser=M('theuser');
        //echo session('username');
        $where['username']=session('username');
        $arr=$theuser->where($where)->select();
        $this->assign(arr,$arr);
        $this->display('index');
    }
    /*学生信息*/
    public function page1(){
        
        /*if($_POST['pass1'])
        {

            if($_POST['pass1']!=""&&$_POST['tel']!=""&&$_POST['email']!="")
            {
                $user = M('theuser');
                $where['username'] = session('username');
                $map['password']=$_POST['pass1'];
                $map['email']=$_POST['email'];
                $map['tel']=$_POST['tel'];
                $user->where($where)->save($map);
                echo "<script>alert('修改成功');</script>";
            }else{
                echo "<script language='javascript'>history.back();</script>";
            }
        }*/

            $theuser=M('theuser');
            $value = session('username');
            $where['username']=$value;
            $sql=$theuser->where($where)->find();
            // var_dump($sql);
            $str="";
            switch ($sql['sex'])
            {
                case 0:
                    $str="男";
                    break;
                case 1:
                    $str="女";
                    break;
            }
            //$this->assign(a,$user->getError());
            $this->assign(sql,$sql);
            $this->assign(str,$str);
            $this->display('page1','utf-8');
    }

    /*培养方案*/
    public function page2(){
        $theuser=M('theuser');
        $value = session('username');
        $where3['username']=$value;
        $sql=$theuser->where($where3)->find();
        $number=$sql['scno'];
        $information=M('information');
        $where2['type']=$number;
        $sql2=$information->where($where2)->select();//专业课
        $count2=$information->where($where2)->count();
        $where['type']=array('lt',10);
        $sql3=$information->where($where)->select();//非专业课
        $count1=$information->where($where)->count();

        $str=array();
        for ($i=0;$i<$count1;$i++)
        {
            switch ($sql3[$i]['type'])
            {
                case 0:
                    $str[$i]="公共基础平台课/数学课";
                    break;
                case 1:
                    $str[$i]="公共基础平台课/英语课";
                    break;
                case $number:
                    $str[$i]="学科专业课";
                    break;
            }
        }
        $str2=array();
        for ($i=0;$i<$count1;$i++)
        {
            switch ($sql2[$i]['type'])
            {
                case 0:
                    $str2[$i]="公共基础平台课/数学课";
                    break;
                case 1:
                    $str2[$i]="公共基础平台课/英语课";
                    break;
                case $number:
                    $str2[$i]="学科专业课";
                    break;
                default:
                    $str2[$i]="cuowu";
                    break;
            }
        }
        $this->assign(sql2,$sql2);
        $this->assign(sql3,$sql3);
        $this->assign(count1,$count1);
        $this->assign(count2,$count2);
        $this->assign(Nu,1);
        $this->assign(Nu2,1);
        $this->assign(str,$str);
        $this->assign(str2,$str2);
        $this->display('page2','utf-8');
    }

    /**
     * Personal表中：0表示未修 1表示已修 2表示重修
     */

    /*成绩查询*/
    public function page3(){
        $Personal=M('personal');//表
        $value = session('id');//缓存id
        //echo $value;
        $where4['id']=$value;
        $Personal1=$Personal->where($where4)->count();
        //echo $Personal1;
        $Personal2=$Personal->where($where4)->select();
        //var_dump($Personal2);
        //以下内容可以化简
        $theuser=M('theuser');
        $sql=$theuser->where($where4)->find();
        $number=$sql['scno'];
        $information=M('information');

        $where3['type']=$number;
        $sql2=$information->where($where3)->select();
        $count2=$information->where($where3)->count();//专业课

        $where['type']=array('lt',10);
        $sql3=$information->where($where)->select();
        $count3=$information->where($where)->count();//非专业课

        //没有选修的专业课
        $arr2=array();
        $a=0;
        for($i=0;$i<$count2;$i++)
        {
            for($j=0;$j<$Personal1;$j++)
            {
                if(($Personal2[$j]['idtwo']!=$sql2[$i]['idtwo'])&&($j==$Personal1-1))
                {
                    $sql2[$i]['idtwo']=sprintf("%06d",$sql2[$i]['idtwo']);
                    $arr2[$a++]=$sql2[$i];
                } elseif ($sql2[$i]['idtwo']==$Personal2[$j]['idtwo'])
                {
                    break;
                }
            }
        }

        //没有选修的非专业课
        $arr3=array();
        $b=0;
        for($i=0;$i<$count3;$i++)
        {
           
           for($j=0;$j<$Personal1;$j++)
           {
               if(($Personal2[$j]['idtwo']!= $sql3[$i]['idtwo'])&&($j==$Personal1-1))
               {
                   $sql3[$i]['idtwo']=sprintf("%06d",$sql3[$i]['idtwo']);
                   $arr3[$b++]=$sql3[$i];
               }elseif ($sql3[$i]['idtwo']==$Personal2[$j]['idtwo'])
               {
                   break;
               }
           }
        }

        //选修结果
        $arr=array();
        $si=array();
        $sitwo=array();
        $sum=0;
        $sum2=0;
        $sum3=0;
        for ($i=0;$i<$Personal1;$i++)
        {
            $idtwo = $Personal2[$i]['idtwo'];
            $Personal2[$i]['idtwo']=sprintf("%06d",$Personal2[$i]['idtwo']);
            $where2['idTwo']=$idtwo;
            $arr[$i]=$information->where($where2)->find();

            switch ($Personal2[$i]['condition'])
            {
                case 0:
                    $si[$i]="当前还没有选修改课程";
                    break;
                case 1:
                    $si[$i]="初修获得";
                    break;
                case 2:
                    $si[$i]="重修获得";
                    break;
            }

            switch ($arr[$i]['type'])
            {
                case 0:
                    $sitwo[$i]="学科基础平台课/数学课";
                    break;
                case 1:
                    $sitwo[$i]="学科基础平台课/英语课";
                    break;
                case 10:
                    $sitwo[$i]="学科基础平台课/必修课";
                    break;
                default:
                    $sitwo[$i]="其他类型";
                    break;
            }
            $sum+=$Personal2[$i]['chengji'];
            $sum2+=$arr[$i]["score"];
            $sum3+=$arr[$i]["score"]*$Personal2[$i]['chengji'];
        }

        $avg2=$sum/$Personal1;
        $avg=$sum3/$sum2;
        $this->assign(si,$si);
        $this->assign(sitwo,$sitwo);
        $this->assign(arr,$arr);
        $this->assign(Personal1,$Personal1);
        $this->assign(Personal2,$Personal2);
        $this->assign(no,1);
        $this->assign(sum,$sum);
        $this->assign(sum2,$sum2);
        $this->assign(sum3,$sum3);
        $this->assign(avg,$avg);
        $this->assign(avg2,$avg2);
        $this->assign(b,$b);
        $this->assign(a,$a);
        $this->assign(arr2,$arr2);
        $this->assign(arr3,$arr3);
        $this->display('page3','utf-8');

    }


    public function page4(){
        $user = D('information');
        $count = $user->count();
        $page = new Page($count, 2);
        $page->setConfig('first','首页');
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $page->setConfig('last','末页');
        $page->setConfig('theme', ' 共 %TOTAL_ROW% 条数据 共%TOTAL_PAGE%页 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show = $page->show();
        $list = $user->limit($page->firstRow, $page->listRows)->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->assign('a', "a");
        $this->display('page4','utf-8') ;
    }


    public function page5(){
        $teacher=D('teacher');
        $information=D('information');
        $select=D('select');
        $where['id']='10101010';
        $count1= $teacher->where($where)->count();
        $sql1=$teacher->where("a.idTwo = b.tclass")->table(array('information'=>'a','teacher'=>'b'))->select();
        $this->assign(sql1,$sql1);
        $where2['tid']='10101010';
        $where2['tclass']=$_GET['a'];
        $count2= $select->where($where2)->count();
        $sql2=$select->where("a.idTwo = b.tclass")->table(array('information'=>'a','teacher'=>'b'))->select();
        $this->assign(sql2,$sql2);
        $this->display('page5','utf-8');
    }
}